package org.deon.branch.install.maven;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

/**
 * @author xiexy
 * @Date 2022/9/26
 * @Description
 */
@Mojo(name = "set", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = false)
public class GitBranchInstallMojo extends AbstractMojo {

    @Parameter(defaultValue = "${project}", readonly = true)
    MavenProject project;

    @Parameter(property = "installVersion")
    String installVersion;

    @Parameter(property = "packageVersion")
    String packageVersion;

    public void execute() throws MojoExecutionException {
        if (installVersion != null && installVersion.trim().length() > 0) {
            project.getArtifact().setVersion(installVersion);
            //打包类型为pom时使用的版本信息
            project.setVersion(installVersion);
            getLog().info("setting install version: " + installVersion);
        }
        if (packageVersion != null && packageVersion.trim().length() > 0) {
            String name = project.getArtifact().getArtifactId() + "-" + packageVersion;
            project.getBuild().setFinalName(name);
            getLog().info("setting package version: " + packageVersion);
        }

    }
}
